package com.lcn.controller;


import com.lcn.grace.result.GraceJSONResult;
import com.lcn.pojo.netty.ChatMsg;
import com.lcn.rabbitmq.RabbitMQTestConfig;
import com.lcn.tasks.SmsTask;
import com.lcn.utils.JsonUtils;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class TestController {

    @Resource
    private SmsTask smsTask;

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/hello")
    public Object hello() {
        return "Hello World";
    }

    @GetMapping("/sendSms")
    public Object sendSms(String mobile, String code) {
        smsTask.sendSms(mobile, code);
        return "Send SMS success";
    }

    @GetMapping("/testSendMQ")
    public GraceJSONResult testSendMQ() {
        ChatMsg chatMsg = new ChatMsg();
        chatMsg.setMsg("hello world");
        String msg = JsonUtils.objectToJson(chatMsg);
        rabbitTemplate.convertAndSend(RabbitMQTestConfig.EXCHANGE_NAME, "com.lcn.test", msg);
        return GraceJSONResult.ok();
    }

}
